package com.spic.system.controller;

import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import com.spic.system.domain.SysAnnounceReceiver;
import com.spic.system.service.ISysAnnounceReceiverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 接收人信息Controller
 *
 * @author spic
 * @date 2022-06-15
 */
@RestController
@RequestMapping("/receiver")
public class SysAnnounceReceiverController extends BaseController
{
    @Autowired
    private ISysAnnounceReceiverService sysAnnounceReceiverService;

    /**
     * 查询接收人信息列表
     */
    @PreAuthorize(hasPermi = "system:receiver:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAnnounceReceiver sysAnnounceReceiver)
    {
        startPage();
        List<SysAnnounceReceiver> list = sysAnnounceReceiverService.selectSysAnnounceReceiverList(sysAnnounceReceiver);
        return getDataTable(list);
    }

    /**
     * 导出接收人信息列表
     */
    @PreAuthorize(hasPermi = "system:receiver:export")
    @Log(title = "接收人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAnnounceReceiver sysAnnounceReceiver) throws IOException
    {
        List<SysAnnounceReceiver> list = sysAnnounceReceiverService.selectSysAnnounceReceiverList(sysAnnounceReceiver);
        ExcelUtil<SysAnnounceReceiver> util = new ExcelUtil<SysAnnounceReceiver>(SysAnnounceReceiver.class);
        util.exportExcel(response, list, "接收人信息数据");
    }

    /**
     * 获取接收人信息详细信息
     */
    @PreAuthorize(hasPermi = "system:receiver:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysAnnounceReceiverService.selectSysAnnounceReceiverById(id));
    }

    /**
     * 新增接收人信息
     */
    @PreAuthorize(hasPermi = "system:receiver:add")
    @Log(title = "接收人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAnnounceReceiver sysAnnounceReceiver)
    {
        return toAjax(sysAnnounceReceiverService.insertSysAnnounceReceiver(sysAnnounceReceiver));
    }

    /**
     * 修改接收人信息
     */
    @PreAuthorize(hasPermi = "system:receiver:edit")
    @Log(title = "接收人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAnnounceReceiver sysAnnounceReceiver)
    {
        return toAjax(sysAnnounceReceiverService.updateSysAnnounceReceiver(sysAnnounceReceiver));
    }

    /**
     * 删除接收人信息
     */
    @PreAuthorize(hasPermi = "system:receiver:remove")
    @Log(title = "接收人信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAnnounceReceiverService.deleteSysAnnounceReceiverByIds(ids));
    }
}
